package cn.webrx;

import java.util.ArrayList;
import java.util.LinkedList;

public class LinkedList2 {
    public static void main(String[] args) {
        int size = 100000;
        long st = System.currentTimeMillis();
        var list1 = new ArrayList<String>();
        for (int i = 0; i <= size; i++) {
            list1.add(0, "list" + i);
        }
        long et = System.currentTimeMillis();
        System.out.printf("List：%d%n",et-st);


        st = System.currentTimeMillis();
        var list2 = new LinkedList<String>();

        for (int i = 0; i <= size; i++) {
            list2.addFirst("list2" + i);
        }
        et = System.currentTimeMillis();
        System.out.printf("LinkedList：%d%n",et-st);

        //list1 (ArrayList)
        st = System.currentTimeMillis();
        for (int i = 0; i <= size; i++) {
            list1.get(i);
        }
        et = System.currentTimeMillis();
        System.out.printf("List：%d%n",et-st);

        //list2 (LinkedList)
        st = System.currentTimeMillis();


        //将LinkedList 转换 ArrayList
        var list3 = new ArrayList<String>(list2);
        for (int i = 0; i <= size; i++) {
            list3.get(i);
        }
        et = System.currentTimeMillis();
        System.out.printf("LinkedList：%d%n",et-st);

    }
}
